let arr = [1, 2, 5, 9, 3, 6, 8, 4, 7]

function quickSort(arr) {
  if (arr.length <= 1) return arr
  let s = Math.floor(arr.length / 2)
  // console.log(s)
  // let temp = arr.splice(s)[0] 错误写法
  let temp = arr.splice(s, 1)[0]
  console.log(temp)
  let left = []
  let right = []
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] < temp) {
      left.push(arr[i])
    } else {
      right.push(arr[i])
    }
  }
  return quickSort(left).concat(temp, quickSort(right))
}

console.log(quickSort(arr))